<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="njtc" uri="http://www.njtcedu.cn/app/core" %>

<div class="content" id="content" data-nav="nav_content">
    <h1>微博列表<span></h1>
    
    <div class="manage">
        <form action="${pageContext.request.contextPath}/contentlist/10" method="post" id="contentSearch" class="filter">
            <label for="userName">用户：</label>
            <input type="text" name="userName" id="userName"/>
			
			<label for="signupDateFrom">发送日期:</label>
			<input type="text" name="sendDate1" id="sendDate" class="dateinput"/>
			
            <input type="submit" value="搜索"/>
        </form>
        
        <c:if test="${not empty pageModel}">
	        <div class="itemList contentList">
	            <table>
	                <thead>
		                <tr>
		                   <th>用户名称</th>	
		                   <th>发送内容</th>
				           <th>发送日期</th>
				           <th></th>
		                </tr>
	                </thead>  
	                 
	                <tbody id="contentList" data-pagenav="contentPageNav">
					<c:choose>
						<c:when test="${not empty pageModel.records}">
							<c:forEach var="contentResponse" items="${pageModel.records}">
								<tr>
									<td>${ contentResponse.userName }</td>
									<td>${ contentResponse.content }</td>
									<td><fmt:formatDate value="${ contentResponse.sendDate }"  type="both" pattern="yyyy-MM-dd HH:mm"/></td>
									<td><a href="${pageContext.request.contextPath}/content/delete/${ contentResponse.contentId}" class="deleteContent">删除</a></td>
								</tr>
							</c:forEach>
						</c:when>
						<c:otherwise>
								<tr>
									<td colspan="25">No Recodes.</td>
								</tr>
						</c:otherwise>
					</c:choose>
	                </tbody>
	            </table>
	            <njtc:pageQuery url="${pageContext.request.contextPath}/contentlist" pageNo="${pageModel.pageNo}"  pageSize="${pageModel.pageSize}"  totalRecords="${pageModel.totalRecords}"/>
	        </div>
        </c:if>
    </div>
</div>
<script>
    $('.deleteContent').ajaxBind(
	    {
	       type: 'DELETE'
	    },
		{
	        onSuccess: function(data, self){
	        	if(data){
	        		self.parents('tr').remove();
	        	}
	        }
	    }
    );
    
    $('.pageNav').each(function(){
    	 var select = $(this);
		 var remoteUrl = select.data('remote');
		 if(!remoteUrl) return;
		 $(this).find("select").change(function(){
			location.href= remoteUrl+ "/1/" + $(this).val();
		 });
		 
    });
</script>